#include "Security.h"
#include "Storage.h"
#include "nor_flash.h"

short Key_flag=0;
short Loge[(Logo_X1-Logo_X0)*(Logo_Y1-Logo_Y0)];
short CheckStartLogo(void)
{
    short Flash_Data;    
    //ReadFlash(FLASHAPP_START_ADDRESS_LOGOPIC, Flash_Data);
    Flash_ReadData(FLASHAPP_START_ADDRESS_LOGOPIC, 1 , 1, &Flash_Data);
    if(Flash_Data == 0x64d9)
        return 1;
    else
        return 0;
}
void Acquire_Reconfig(void)
{
static short acquire_type;    
    if(Key_flag==1)
    {
        char acquire_reg[6]={0},i,j,k;
        acquire_type++;
        i=acquire_type%5;
        if(i==0)
        {
            j=acquire_type%400;
            k=acquire_type%240;
            acquire_reg[0]=ACQUIRE_IMPORTANT_REG2>>8;
            acquire_reg[1]=ACQUIRE_IMPORTANT_REG2;
            acquire_reg[2]=ACQUIRE_IMPORTANT_REG3>>8;
            acquire_reg[3]=ACQUIRE_HARDWARE_REG3;
            acquire_reg[4]=ACQUIRE_IMPORTANT_REG3;            
        }
        else
        {
            j=800-acquire_type%400;
            k=480-acquire_type%240;
            acquire_reg[0]=ACQUIRE_HARDWARE_REG1>>8;
            acquire_reg[1]=ACQUIRE_HARDWARE_REG1;
            acquire_reg[2]=ACQUIRE_HARDWARE_REG2>>8;
            acquire_reg[3]=ACQUIRE_HARDWARE_REG2;
            acquire_reg[4]=ACQUIRE_HARDWARE_REG3>>8;            
        }
        GUI_mbsTextOut(j, k, acquire_reg, GUI_YELLOW);
    }
}
short CheckDisplayLogo(void)
{
    short i,j;
    for(j=0;j<(Logo_Y1-Logo_Y0);j++)
        for(i=0;i<(Logo_X1-Logo_X0);i++)
            if(*(gDisplayBuffer+i+Logo_X0+800*j)!=Loge[i+j*(Logo_X1-Logo_X0)])
                return 0;
    return 1;
            
}

void WriteLogoToFlash(void)
{
    Flash_WriteData(FLASHAPP_START_ADDRESS_LOGOPIC, (Logo_X1-Logo_X0)*(Logo_Y1-Logo_Y0), Loge, 1,false);
}

